﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace S4Store.Models.AfterSaleReport
{
    public class AfterSaleProductModel : BaseReportModel
    {
        public List<Domain.AfterSaleKpi.MonthStandardConfig> StandardConfigs { get; set; }
        public List<Domain.AfterSaleKpi.AfterSaleCarDecoratingMonthConfig> DMMonthTargets { get; set; }
        public List<Domain.AfterSaleKpi.AfterSaleCarDecoratingDayInput> DMDayDatas { get; set; }

        #region 用品部分公式
        /// <summary>
        /// 目标单车装潢销售总额
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_MBDCZHXSZE(int year, int month)
        {
            if (DMMonthTargets == null) return 0;
            return DMMonthTargets.Where(o => o.AddTime.Year == year && o.AddTime.Month == month).Sum(o => o.ZHEMB_DecoratingTargetValume);
        }

        /// <summary>
        /// 累计装潢销售总额
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_LJZHXSZE(int year, int month)
        {
             if (DMDayDatas == null) return 0;
             return DMDayDatas.Where(o => o.AddTime.Year == year && o.AddTime.Month == month)
                 .Sum(o => o.ZHXSZE_DecoratingSalesTotalVolume);
        }

        /// <summary>
        /// 装潢销售进度
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_ZHXSJD(int year,int month)
        {
            var d1 = z_MBDCZHXSZE(year, month);
            var d2 = z_LJZHXSZE(year, month);
            if (d1 == 0 || d2 == 0) return 0;
            return Math.Round(d2 / d1 * 100, 2, MidpointRounding.AwayFromZero);
        }



        #endregion


        #region 养护产品部分公式
        /// <summary>
        /// 养护产品销售额目标总额
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_YHCPXSEMBZE(int year, int month)
        {
            if (DMMonthTargets == null) return 0;
            return DMMonthTargets.Where(o => o.AddTime.Year == year && o.AddTime.Month == month).Sum(o => o.YHCPXSEMB_SaleMaintenanceTargetValume);
        }

        /// <summary>
        /// 累计养护产品销售总额
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_LJYHCPXSZE(int year, int month)
        {
            if (DMDayDatas == null) return 0;
            return DMDayDatas.Where(o => o.AddTime.Year == year && o.AddTime.Month == month)
                .Sum(o => o.YHCPXSZE_MaintenceSaleTotalVolume);
        }

        /// <summary>
        /// 养护产品销售进度
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal z_YHCPXSJD(int year, int month)
        {
            var d1 = z_YHCPXSEMBZE(year, month);
            var d2 = z_LJYHCPXSZE(year, month);
            if (d1 == 0 || d2 == 0) return 0;
            return Math.Round(d2 / d1 * 100, 2, MidpointRounding.AwayFromZero);
        }



        #endregion
    }
}